
/**
 * 仿写后端数据转对象
 * @param {String} strObj 
 * @returns Object
 */
   function parse(jsonDate){
    //1.去掉所有的空格 "" 
    let str= jsonDate.replace(/['{}]/g,'')
    //console.log(str);
    //2.按照逗号分隔
    let arr=str.split(",")
    let obj = {}
    //3.遍历
    arr.forEach(item=>{
    //4.按照冒号分割
    let temp=item.split(":")
    //console.log(temp);
    //5.第一个值为索引，第二个为值,加上判断
    temp[0]=temp[0].replace(/"|\s/g,'')
    temp[1]=temp[1].replace(/\s/g,'')
    if(temp[1] === "true"){
    temp[1] = Boolean(temp[1])
    }else if(temp[1] === 'false'){
        temp[1] = false
    }else if(temp[1] === 'null'){ 
        temp[1] = null
    }else if(temp[1] === 'undefined'){
        temp[1] = undefined
    }else if(isNaN(Number(temp[1])) ){
        temp[1]=temp[1].replace(/"/g,'')
    }else{
        temp[1]= Number(temp[1])
    }
    obj[temp[0]]=temp[1]
    })
    return obj              
    }
    // let jsonDate='{"a":0,"b":"ok","c":null,"d":undefined,"e":true,"f":false}'  //=>{a:0,b:"ok",c:null,d:undefined,e:true,f:"false"}   
    // console.log(parse(jsonDate))            


 /**
 * 将对象转换为后端JSON数据
 * @param {*} strObj 
 */

                                                                                                                                                                                    

function Stringify(obj){
    let arr=[]
    //1遍历对象for in

    for(let key in obj ){
    let val=obj[key] 
    if(["boolean","number"].includes(typeof val )){
        val=obj[key] 
    }else{
        val=`"${obj[key]}"`
    }
    arr.push(`"${key}":${val}`)
    }
    return `{${arr.join(",")}}`
}
//2.循环上面定义空数组，循环里面拼接“键”：值 push到数组中
//3.数组变字符串

    
    
    